import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger bigInteger = new BigInteger("2");
        bigInteger = bigInteger.pow(64);

        int t = scanner.nextInt();
        while (t > 0) {
            t--;
            int n = scanner.nextInt(); //行
            int m = scanner.nextInt(); //列
            int q = scanner.nextInt(); //q次询问
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = scanner.nextLong();
                }
            }

            //创建二维前缀和数组
            long[][] dp = new long[n + 1][m + 1];
            for (int i = 1; i < n + 1; i++) {
                for (int j = 1; j < m + 1; j++) {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i - 1][j - 1];
                }
            }

            List<Long> list = new ArrayList<>();
            while (q > 0) {
                q--;
                int u = scanner.nextInt();
                int v = scanner.nextInt();
                int x = scanner.nextInt();
                int y = scanner.nextInt();
                long num = dp[x][y] - dp[x][v - 1] - dp[u - 1][y] + dp[u - 1][v - 1];
//                System.out.println(num);
                list.add(num);
            }

            long ret = 0;
            for (long i : list) {
                ret ^= i;
            }

            System.out.println(ret);

        }

        scanner.close();
    }
}
